package com.dream.service.impl;

import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dream.able.CommentMapper;
import com.dream.datasource.DBContextHolder;
import com.dream.pojo.Comment;
import com.dream.service.able.All_Service_able;


/*
 * 文章评论业务类
 */
@Service("Comment_Serviceimpl")
public class Comment_Serviceimpl implements All_Service_able<Comment> {
	
	/*
	 * 文章评论表的DAO代理对象
	 */
	@Resource(name="commentMapper")
	private CommentMapper comment_mapper;
	
	/*
	 * (提交评论,依次传入的为，用户id，评论内容，文章id，)
	 * @see com.dream.service.able.All_Service_able#insert(java.lang.String[])
	 */
	@Override
	public Comment insert(String... str) {
		//切换数据源,主库
		DBContextHolder.setDbType(DBContextHolder.master);
		//创建文章评论对象
		Comment comment = new Comment();
		//插入用户
		comment.setUid(Integer.parseInt(str[0]));
		//插入标题
		comment.setContext(str[1]);
		//插入关联的文章
		comment.setAid(Integer.parseInt(str[2]));
		//插入状态
		comment.setState(1);
		//插入时间
		comment.setTime(new Date());
		//将对象写入数据库
		return comment_mapper.insertSelective(comment)>0?comment:null;
	}

	@Override
	public List<Comment> list() {
		return null;
	}

	@Override
	public Comment getT(String... str) {
		return null;
	}

}
